from django.db import models


# Create your models here.

class Suser(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=250)
    types = models.IntegerField()  # 1vip,2普通用户
    num = models.IntegerField(default=0)

    class Meta:
        db_table = 'suser'


class Sshop(models.Model):
    name = models.CharField(max_length=20)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    user = models.ManyToManyField(Suser, related_name='users', null=True, blank=True)

    class Meta:
        db_table = 'sshop'


class Scom(models.Model):
    user = models.ForeignKey(Suser, on_delete=models.CASCADE)
    shop = models.ForeignKey(Sshop, on_delete=models.CASCADE)
    comtent = models.TextField()

    class Meta:
        db_table = 'scom'


class Author(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=250)
    types = models.IntegerField()

    class Meta:
        db_table = 'author'


class Abook(models.Model):
    name = models.CharField(max_length=20)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    pic = models.ImageField(null=True)
    au = models.ForeignKey(Author, on_delete=models.CASCADE)

    class Meta:
        db_table = 'abook'


class Movie(models.Model):
    name = models.CharField(max_length=20)
    pic = models.ImageField()
    mtime = models.DateField()

    class Meta:
        db_table = 'movie'


class Actor(models.Model):
    mo = models.ForeignKey(Movie, on_delete=models.CASCADE)
    name = models.CharField(max_length=20)
    age = models.IntegerField()
    sex = models.IntegerField()  # 1是男，2是女
    movie = models.ManyToManyField(Movie, null=True, blank=True, related_name='yan')

    class Meta:
        db_table = 'actor'
